//
//  UIColorExtension.swift
//  Nahuo
//
//  Created by zang qilong on 2017/5/8.
//  Copyright © 2017年 zang qilong. All rights reserved.
//

import Foundation
import UIKit

extension UIColor {
    public class func bgColor() -> UIColor {
        return UIColor.RGB(r: 249, g: 249, b: 249)
    }
    
    public class func titleColor() -> UIColor {
        return UIColor.RGB(r: 51, g: 51, b: 51)
    }
    
    public class func codeTextFieldBorderColor() -> UIColor {
        return UIColor.RGB(r: 31, g: 180, b: 156)
    }
    
    public class func tableBGColor() -> UIColor {
        return UIColor.RGB(r: 238, g: 238, b: 238)
    }
    
    class func RGB(r:Float, g:Float, b:Float) -> UIColor{
        return UIColor(colorLiteralRed: r/255, green: g/255, blue: b/255, alpha: 1);
    }
    
    class func appThemeColor() -> UIColor {
        return UIColor.RGB(r: 31, g: 180, b: 156)
    }
    
    class func hexStringToUIColor (hex:String) -> UIColor {
        var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
        
        if (cString.hasPrefix("#")) {
            cString.remove(at: cString.startIndex)
        }
        
        if ((cString.characters.count) != 6) {
            return UIColor.gray
        }
        
        var rgbValue:UInt32 = 0
        Scanner(string: cString).scanHexInt32(&rgbValue)
        
        return UIColor(
            red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
            green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
            blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
            alpha: CGFloat(1.0)
        )
    }
}
